package com.jvm.memory;

/**
 * 可导致虚拟机栈溢出的demo
 */
public class MyTest2 {

    private int length;

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public void test(){
        this.length++;
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        test();
    }

    public static void main(String[] args) {
        MyTest2 myTest2 = new MyTest2();
        try{
            myTest2.test();
        }catch (Throwable ex){
            System.out.println(myTest2.getLength());
            ex.printStackTrace();
        }

    }
}
